#ifndef RGSLAYERTREEVIEWMENUPROVIDER_H
#define RGSLAYERTREEVIEWMENUPROVIDER_H
#include<QtMath>
#include <QObject>

#include <qgslayertreeview.h>
#include <qgsmaplayer.h>
#include <QList>

class QAction;
struct LegendLayerAction
{
    LegendLayerAction( QAction* a, QString m, QString i, bool all )
        : action( a ), menu( m ), id( i ), allLayers( all ) {}
    QAction* action;
    QString menu;
    QString id;
    bool allLayers;
    QList<QgsMapLayer*> layers;
};
class QgsMapCanvas;

class rgslayertreeviewmenuprovider:public QObject, public QgsLayerTreeViewMenuProvider
{
    Q_OBJECT
public:
    rgslayertreeviewmenuprovider(QgsLayerTreeView *view, QgsMapCanvas* canvas);
    ~rgslayertreeviewmenuprovider();

    //! 重写这个方法来获取右键菜单
    QMenu* createContextMenu() override;

    void addLegendLayerAction( QAction* action, QString menu, QString id,
                              QgsMapLayerType  type, bool allLayers );
    bool removeLegendLayerAction( QAction* action );
    void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer );
    void removeLegendLayerActionsForLayer( QgsMapLayer* layer );
    QList< LegendLayerAction > legendLayerActions( QgsMapLayerType  type ) const;

protected:

    void addCustomLayerActions( QMenu* menu, QgsMapLayer* layer );

    QgsLayerTreeView* mView;
    QgsMapCanvas* mCanvas;

    QMap<QgsMapLayerType, QList< LegendLayerAction>> mLegendLayerActionMap;
};

#endif // RGSLAYERTREEVIEWMENUPROVIDER_H
